package com.example.demo.controller;


import com.example.demo.entity.Wallet;
import com.example.demo.service.IWalletService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.math.BigDecimal;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author hjh
 * @since 2023-02-15
 */
@RestController
@RequestMapping("/wallet")
public class WalletController {

    @Autowired
    private IWalletService walletService;


    /**
     * 1.查询用户钱包余额的接口，id为用户id
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public String getBalance(@PathVariable Long id){
        Wallet wallet = walletService.getById1(id);
        return wallet.toString();
    }

    // 2. 用户消费的接口，id为用户id，jine为退款金额
    @GetMapping("/xiaofei/{id}/{jine}")
    public String xiaofei(@PathVariable("id") Long id,
                          @PathVariable("jine") BigDecimal jine){
        String xiaofei = walletService.xiaofei(id, jine);
        return xiaofei;
    }

    // 3. 用户退款接口,id为用户id，jine为退款金额
    @GetMapping("/add/{id}/{jine}")
    public String add(@PathVariable("id") Long id,
                          @PathVariable("jine") BigDecimal jine){
        String add = walletService.add(id,jine);
        return add;
    }


    // 4. 查询用户钱包金额变动明细的接口
    @GetMapping("/mingxi/{id}")
    public String mingxi(@PathVariable("id") Long id){
        String mingxi = walletService.mingxi(id);
        return mingxi;
    }
}
